package demo;

import dao.ClassDao;
import dao.StudentDao;
import model.Classes;
import model.Student;

import java.util.Scanner;

/**
 * @author tongchen
 * @create 2022-12-28 13:02
 */
public class exer1 {
    //实现与用户交互的逻辑
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入你要查询的班级name");
        String className =scan.next();
        //查询班级id
        ClassDao classDao = new ClassDao();
        Classes classIdByName = classDao.getClassIdByName(className);
        //判断是否存在该班级
        if(classIdByName==null){
            System.out.println("不存在该班级");
            return;
        }
        System.out.println("查询成功,班级id:"+classIdByName.getId());
        //进行插入操作
        Student student = new Student();
        System.out.println("请输入学生姓名");
        String name=scan.next();
        student.setName(name);
        System.out.println("请输入学号");
        student.setSn(scan.nextInt());
        System.out.println("请输入email");
        student.setEmail(scan.next());
        System.out.println("请输入班级id");
        student.setClassId(scan.nextInt());
        //插入操作
        StudentDao studentDao = new StudentDao();
        int insert = studentDao.insert(student);
        if(insert>0){
            System.out.println("新增成功");
        }
        else{
            System.out.println("新增失败");
        }


    }
}
